<template>
  <div class="seachPlayList">
    <!-- 歌曲 -->
    <div v-if="activeIndex == 0">
      <div
        class="seachList-box"
        v-for="(item, index) in MusicPlayData"
        :key="index"
        @click="getURL(item, item.id)"
      >
        <div class="seachList-index">{{ index + 1 }}</div>
        <div class="seachList-left">
          <img class="auto-img" :src="item.al.picUrl" />
        </div>
        <div class="seachList-MusicName">{{ item.name }}</div>
        <div class="seachList-right">
          <div class="MusicSinger">
            {{ MusicPlayData.length > 0 ? item.ar[0].name : "" }}
          </div>
          <div class="MusicList">
            <div class="MusicList-item item0">
              <el-tooltip
                class="item"
                effect="dark"
                content="加入喜欢列表"
                placement="top"
              >
                <img
                  class="auto-img"
                  :src="require('../../assets/image/icon/shoucang_1.png')"
                  alt=""
                />
              </el-tooltip>
            </div>
            <div class="MusicList-item item1">
              <el-tooltip
                class="item"
                effect="dark"
                content="加入歌单"
                placement="top"
              >
                <img
                  class="auto-img"
                  :src="require('../../assets/image/icon/jiahao.png')"
                  alt=""
                />
              </el-tooltip>
            </div>
            <div
              class="MusicList-item item2"
              @click.stop="JOinPlayList(item.id)"
            >
              <el-tooltip
                class="item"
                effect="dark"
                content="加入播放列表"
                placement="top"
              >
                <img
                  class="auto-img"
                  :src="require('../../assets/image/icon/liebiao.png')"
                  alt=""
                />
              </el-tooltip>
            </div>
            <div
              class="MusicList-item item3"
              @click.stop="downloadMusic(item.id,item.name)"
            >
             <DownLoad ref="mychild"/>
              <el-tooltip
                class="item"
                effect="dark"
                content="下载"
                placement="top"
              >
                <img
                  class="auto-img"
                  :src="require('../../assets/image/icon/xiazai.png')"
                  alt=""
                />
              </el-tooltip>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 专辑 -->
    <div v-else-if="activeIndex == 1">
      <div
        class="seachCon-box"
        v-for="(item, index) in albumData"
        :key="index"
        @click="cheakInfomation(item.id, 'album')"
      >
        <div class="seachCon-con">
          <div class="seach-List-img">
            <img class="auto-img" :src="item.picUrl" alt="" />
          </div>
          <div class="seachCon-text">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <!-- 歌手 -->
    <div v-else-if="activeIndex == 2">
      <div class="seachPort">
        <div
          class="seachPort-con"
          v-for="(item, index) in artists"
          :key="index"
          @click="cheakInfomation(item.id, 'singer')"
        >
          <div class="seachPort-img">
            <!-- <img class="auto-img" :src="item.picUrl ? item.picUrl : require('../../assets/image/icon/jiazaizhong.gif')" /> -->
            <img v-if="item.picUrl" class="auto-img" :src="item.picUrl" />
            <img
              v-else
              style="width: 20px; height: 20px; display: block; margin: 30px"
              :src="require('../../assets/image/icon/jiazaizhong.gif')"
            />
          </div>
          <div class="seachPort-text">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <!-- 歌单 -->
    <div v-else-if="activeIndex == 3">
      <div class="seachPlay">
        <div
          class="seachPlay-con clearfix"
          v-for="(item, index) in playlists"
          :key="index"
        >
          <div class="seachPlay-con-left fl">
            <img class="auto-img" :src="item.coverImgUrl" alt="" />
          </div>
          <div class="seachPlay-con-cent fl">
            <div class="cent-top-text">{{ item.name }}</div>
            <div class="cent-bottom-text">
              <div class="cent-NickName">By:{{ item.creator.nickname }}</div>
              <div class="cent-count">
                <img src="../../assets/image/icon/shouting.png" alt="" />:
                {{ item.playCount }}
              </div>
            </div>
          </div>
          <div class="seachPlay-con-trackCount fr">
            {{ item.trackCount }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getMusicDetailInfo, getURLInfo } from "@/Api/seachApi.js";
import DownLoad from '@/components/publicCompontents/DownLoad'
export default {
  name: "SeachPlayList",
  components:{DownLoad},
  props: {
    //   获取音乐ID
    listData: {
      type: Array,
      defalut: [],
    },
    activeIndex: {
      type: Number,
      defalut: 0,
    },
    // 专辑数据
    albumData: {
      type: Array,
      defalut: [],
    },
    // 接收歌手数据
    artists: {
      type: Array,
      defalut: [],
    },
    // 接受搜索歌单数据
    playlists: {
      type: Array,
      defalut: [],
    },
  },
  data() {
    return {
      //   歌曲列表详情
      MusicPlayData: [],
      // 是否查看详情列表
      isCheakInfomate: false,
      // 下载的歌曲名字
      musicDownLoadName: "",
      // 榜单歌曲展示列表
      rankData: [],
      // 歌单歌曲Id
      rankTrackIds: [],
      // 播放全部歌曲
      allplay: [],
      // 推荐歌单中选中后详情的名称
      recomentTitleName: "",

      // 显示推荐歌单详情列表
      isShow: true,
    };
  },
  created() {},
  computed: {
    // 获取audio标签
    getAudioElement() {
      return this.$store.state.musicState.audioElement;
    },
      // 音乐Id
    musicID() {
      return this.$store.state.musicState.musicID;
    },
  },
  methods: {
    // 获取歌曲详情
    getMusicDetail() {
      getMusicDetailInfo(this.listData)
        .then((res) => {
          if (res.code == 200) {
            this.MusicPlayData = res.songs;
            // 下载的歌曲名字
            this.musicDownLoadName = res.songs[0].name;
          }
        })
        .catch((err) => {
          // console.log(err);
        });
    },

    // 点击播放
    getURL(item, id) {
      // console.log(id);
      if (this.musicID === id) {
        return;
      }
      this.$store.commit("musicState/isClickPlay", false);
      getURLInfo({ id: id })
        .then((res) => {
          // console.log(res);
          if (res.code == 200) {
            // this.$store.commit("musicState/audioSrc", res.data[0].url);
            this.$store.commit("musicState/SetMusicID", id);
            this.$store.commit("musicState/SetMusicPlayListData", id);
            // 加入播放列表
            // this.$store.commit("SetMusicPlayListData", id);
            // setTimeout(() => {
            //   this.$store.commit("musicState/isClickPlay", true);
            //   this.getAudioElement.play();
            // }, 800);
          }
        })
        .catch((err) => {
          // console.log(err);
        });
    },
    // 加入播放列表
    JOinPlayList(id) {
      // 加入播放列表
      this.$store.commit("musicState/SetMusicPlayListData", id);
    },
    // 查看详情列表
    cheakInfomation(id, name) {
      // console.log(id, name);
      this.isCheakInfomate = true;
      this.$store.commit("musicState/musicListID", id);
      this.$router.push({ name: "InformationDetails", params: { name } }); //跳转信息详情
    },
    // 下载音乐
    downloadMusic(uid,MusicName) {
       this.$nextTick(() => {
        // console.log("列表", this.$refs.mychild);
        // debugger
        this.$refs.mychild[0].downLoad(uid,MusicName);
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.seachPlayList {
  // 歌曲栏
  .seachList-box {
    width: 100%;
    height: 90px;
    margin-top: 10px;
    padding-bottom: 2px;
    background-color: rgba(0, 0, 0, 0);
    border-bottom: 1px solid #838591;
    color: #d6d6d4;
    display: flex;
    cursor: pointer;

    .seachList-index {
      width: 50px;
      height: 100%;
      line-height: 90px;

      font-size: 28px;
      font-weight: bold;
      margin-right: 20px;
      flex: 1;
    }
    .seachList-left {
      width: 90px;
      height: 100%;
      // background-color: red;
      //  flex: 2  ;
    }
    .seachList-MusicName {
      height: 100%;
      line-height: 90px;
      // background-color: blue;
      font-size: 18px;
      font-weight: bold;
      margin-left: 10px;
      flex: 5;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
    .seachList-right {
      height: 100%;
      flex: 4;
      line-height: 90px;
      padding-left: 40px;
      // background-color: lightgreen;

      position: relative;
      .MusicSinger {
        position: absolute;
        top: 0;
        left: 30px;
        display: block;
        text-align: left;
      }
      .MusicList {
        // display: none;
        height: 100%;
        text-align: left;

        .MusicList-item {
          display: inline-block;
          width: 34px;
          height: 34px;
          vertical-align: middle;
          margin-right: 10px;
          z-index: 100;
          cursor: pointer;
        }
        .item0 {
          transition: all 0.7s;
          transform: translateX(380px);
        }
        .item1 {
          transition: all 0.6s;
          transform: translateX(380px);
        }
        .item2 {
          transition: all 0.5s;
          transform: translateX(380px);
        }
        .item3 {
          transition: all 0.4s;
          transform: translateX(380px);
        }
      }
    }

    &:hover {
      .MusicSinger {
        display: none;
      }
      .MusicList {
        display: block;

        .item0 {
          transition: all 0.4s;
          transform: translateX(0px);
        }
        .item1 {
          transition: all 0.5s;
          transform: translateX(0px);
        }
        .item2 {
          transition: all 0.6s;
          transform: translateX(0px);
        }
        .item3 {
          transition: all 0.6s;
          transform: translateX(0px);
        }
      }
    }
  }
  // 专辑栏
  .seachCon-box {
    width: 100%;
    height: 100%;
    color: #d6d6d4;
    // background-color: #fff;
    .seachCon-con {
      // display: inline-block;
      width: 190px;
      height: 230px;
      // flex: 1;
      float: left;
      margin: 10px 34px;

      border-radius: 10px;
      overflow: hidden;
      // background-color: rgba(255, 255, 255, 0.8);
      .seach-List-img {
        width: 100%;
        height: 190px;
        cursor: pointer;
        // background-color: rgba(255, 255, 255, 0.8);
      }
      .seachCon-text {
        height: 26px;
        line-height: 26px;
        width: 100%;
        font-size: 18px;
        margin: 10px 0;
        text-overflow: ellipsis;
        white-space: normal;
        overflow: hidden;
      }
    }
  }
  // 歌手栏
  .seachPort {
    width: 100%;
    // background-color: #fff;

    .seachPort-con {
      width: 120px;
      height: 150px;
      margin: 36px;
      float: left;

      .seachPort-img {
        width: 120px;
        height: 120px;
        border-radius: 50%;
        // background-color: rgba(0, 0, 0, 0.6);
        overflow: hidden;
        cursor: pointer;

        > img {
          width: 100%;
          height: 100%;
        }
      }
      .seachPort-text {
        padding: 5px 0;
        font-size: 20px;
        font-weight: bold;
        color: #fff;
      }
    }
  }
  // 歌单栏
  .seachPlay {
    width: 100%;
    position: relative;
    // background-color: #fff;
    .seachPlay-con {
      width: 100%;
      height: 150px;
      padding: 20px;
      box-sizing: border-box;
      border-bottom: 1px solid #fff;
      // background-color: rgba(0, 0, 0, 0.6);
      position: relative;

      &:hover {
        // background-color: rgba(0, 0, 0, 0.8);

        .seachPlay-con-left {
          transform: scale(1.2);
        }
        .seachPlay-con-cent {
          transform: scale(0.9);
        }
        .seachPlay-con-trackCount {
          transform: scale(1.2);
        }
      }
    }
    .seachPlay-con-left {
      width: 100px;
      height: 100px;
      border-radius: 20px;
      overflow: hidden;
      // background-color: rgba(0, 0, 0, 0.3);
    }
    .seachPlay-con-cent {
      margin-left: 26px;
      display: flex;
      flex-flow: column;

      .cent-top-text {
        max-width: 460px;
        height: 30px;
        font-size: 20px;
        font-weight: bold;
        color: rgba(255, 255, 255, 0.6);
        text-align: left;
        text-overflow: ellipsis;
        white-space: normal;
        overflow: hidden;
      }
      .cent-bottom-text {
        width: 400px;
        margin-top: 38px;
        font-size: 16px;
        font-weight: bold;
        display: flex;

        .cent-NickName {
          z-index: 20;
          float: left;
          vertical-align: bottom;
          margin-right: 10px;
        }
        .cent-count {
          float: left;
          vertical-align: middle;

          > img {
            width: 26px;
            height: 26px;
            vertical-align: bottom;
          }
        }
      }
    }
    .seachPlay-con-trackCount {
      width: 200px;
      position: absolute;
      right: 20px;
      bottom: 20px;
      display: inline-block;
      text-align: right;
      font-size: 60px;
      font-weight: bold;
    }

    .ranking-con {
      flex: 4;
      width: 70%;
      min-width: 700px;
      height: 70%;
      box-sizing: border-box;
      padding: 20px 10px 10px;
      background-color: rgba(0, 0, 0, 0.6);
      border-radius: 30px;
      overflow: hidden;
      position: absolute;
      top: 5%;
      left: -70%;
      z-index: 100;

      .con-null {
        width: 100%;
        height: 50px;
        line-height: 50px;
        box-sizing: border-box;
        text-align: center;
        font-size: 24px;
        padding: 0 10px;
        margin-bottom: 10px;
        color: rgba(255, 255, 255, 0.8);
        // background-color: rgba(0, 0, 0, 0.6);
      }
      .ranking-con-box {
        width: 100%;
        height: calc(100% - 50px);
        padding: 10px;
        box-sizing: border-box;
      }
    }
    .contain-top {
      width: 100%;
      height: 50px;
      background-color: rgba(0, 0, 0, 0.1);

      .contain-play {
        width: 100%;
        margin-top: 10px;
        height: 50px;
        background-color: rgba(0, 0, 0, 0.2);

        .play-lis {
          width: 120px;
          height: 100%;
          float: right;

          img {
            width: 30px;
            height: 30px;
            margin-right: 5px;
            margin-top: 12px;
            display: inline-block;
            vertical-align: bottom;
          }
        }
      }
    }

    .contain-list {
      width: 100%;
      // height: 680px;
      height: calc(100% - 60px);

      background-color: rgba(0, 0, 0, 0);
      border-radius: 10px;
      overflow: hidden;
      overflow: scroll;
      &::-webkit-scrollbar {
        width: 0px;
      }
      &::-o-scrollbar {
        width: 0px;
      }
      &::-moz-scrollbar {
        width: 0px;
      }

      .contain-list-con {
        width: 100%;
        height: 130px;
        padding: 20px;
        box-sizing: border-box;

        background-color: rgba(255, 255, 255, 0.1);

        .contain-list-nav {
          width: 100%;
          height: 100%;
          overflow: hidden;
          border-bottom: 1px solid #fff;
          position: relative;
        }

        &:hover {
          .contain-list-nav {
            border: none;
            background-color: rgba(255, 255, 255, 0.2);
            box-shadow: 0px 0px 3px 1px rgba(255, 255, 255, 0.6);
          }
          .contain-index {
            color: rgba(255, 255, 255, 0);
          }
          .contain-list-con-left {
            transition: all 0.3s;
            transform: translateX(-70px);
          }

          .cent-top-name {
            transition: all 0.3s;
            transform: translateX(-80px);
          }
          .cent-top-text {
            min-width: 240px;
            transition: all 0.3s;
            transform: translateX(-80px);
            overflow: hidden; //超出的文本隐藏
            text-overflow: ellipsis; //溢出用省略号显示
            white-space: nowrap; //溢出不换行
          }
          .item0 {
            transition: all 0.4s;
            transform: translateY(0px);
          }
          .item1 {
            transition: all 0.5s;
            transform: translateY(0px);
          }
          .item2 {
            transition: all 0.6s;
            transform: translateY(0px);
          }
          .item3 {
            transition: all 0.6s;
            transform: translateY(0px);
          }
        }
      }
      .contain-index {
        width: 60px;
        height: 100%;
        font-size: 80px;
        font-weight: 900;
        margin-right: 10px;
        color: rgba(255, 255, 255, 0.6);
        position: relative;
        // background-color: rgba(0, 0, 0, 0.1);

        span {
          position: absolute;
          bottom: -26px;
          left: calc(50% - 26px);
        }
      }
      .contain-list-con-left {
        width: 90px;
        height: 90px;
        border-radius: 20px;
        overflow: hidden;
        transition: all 0.3s;
        transform: translateX(0px);
        background-color: rgba(0, 0, 0, 0.3);
      }
      .contain-list-con-cent {
        margin-left: 26px;
        display: flex;
        flex-flow: column;
        text-align: left;

        .cent-top-name {
          width: 200px;
          font-size: 20px;
          margin-top: 10px;
          font-weight: bold;
          color: rgba(255, 255, 255, 0.6);
          transition: all 0.3s;
          transform: translateX(0px);
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
        }
        .cent-top-text {
          width: 100px;
          max-width: 200px;
          min-width: 200px;
          font-size: 20px;
          margin-top: 10px;
          font-weight: bold;
          transition: all 0.3s;
          transform: translateX(218px);
          text-align: right;
          color: rgba(255, 255, 255, 0.6);
        }
      }
      .contain-list-con-trackCount {
        height: 100%;
        line-height: 130px;
        float: right;
        margin-right: 10px;

        .con-list-item {
          display: inline-block;
          width: 30px;
          height: 30px;
          vertical-align: middle;
          margin-right: 10px;
          transition: all 0.3s;
          transform: translateY(50px);
          cursor: pointer;
          z-index: 100;
        }
      }
    }
  }
}
</style>
